﻿using Contrib.SecuredSocketsLayer.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using Orchard.Environment.Extensions;
using Orchard.Localization;

namespace Contrib.SecuredSocketsLayer.Drivers {
    public class SslSettingsPartDriver : ContentPartDriver<SslSettingsPart> {
        private const string TemplateName = "Parts/SecuredSocketsLayer.Settings";

        public SslSettingsPartDriver() {
            T = NullLocalizer.Instance;
        }

        public Localizer T { get; set; }

        protected override string Prefix { get { return "SslSettings"; } }

        protected override DriverResult Editor(SslSettingsPart part, dynamic shapeHelper) {
            return ContentShape("Parts_SslSettings_Edit",
                    () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix));
        }

        protected override DriverResult Editor(SslSettingsPart part, IUpdateModel updater, dynamic shapeHelper) {
            updater.TryUpdateModel(part, Prefix, null, null);

            return ContentShape("Parts_SslSettings_Edit",
                    () => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: part, Prefix: Prefix));
        }
    }
}